//
//  DKTabBar.m
//  微豆客
//
//  Created by wangzhaohui-Mac on 14-7-24.
//  Copyright (c) 2014年 com.Itheima. All rights reserved.
//

#import "WKTabBar.h"
#import "UIView+Extension.h"

@interface WKTabBar ()

@end


@implementation WKTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
         self.backgroundColor = WKColor(73, 187, 173);
        [self setBackgroundColor:WKColor(73, 187, 173)];
    }
    return self;
}


- (void)click
{
    //如果代理方法有响应
    if ([self.WKtabBarDelegate respondsToSelector:@selector(tabBarDidClickedPlusButton:)]) {
        [self.WKtabBarDelegate tabBarDidClickedPlusButton:self];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //设置所有TabBarButton的frame
    [self setAllTabBarButtonsFrame];
    
}

- (void)setAllTabBarButtonsFrame
{
    int index = 0;
    
    for (UIView *tabBarButton in self.subviews) {
        //如果不是UITabBarButton，就跳过，继续遍历
        if(![tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) continue;
        
        //调整tabBarButton的frame
        [self setTabBarButtonFrame:tabBarButton index:index];
        
        index++;
    }
}
/**
 设置taBarButton的frame
 */
- (void)setTabBarButtonFrame:(UIView *)taBarButton index:(int)index
{
    CGFloat btnW = self.width/(self.items.count);
    CGFloat btnH = self.height;
    
    taBarButton.width = btnW;
    taBarButton.height = btnH;
    if (index >= 2) {
        taBarButton.x = btnW * (index);
    }else
    {
        taBarButton.x = btnW * index;
    }
    taBarButton.y = 0;
    
}


@end
